<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('资本账户') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('出资人名称')" prop="investorId">
        <el-select v-model="queryParams.investorId" filterable clearable>
          <el-option
            v-for="item in investorOptions"
            :key="item.id"
            :label="item.userName"
            :value="item.id"
          />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t("重置") }}</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="fundCapitalAccountList" border tooltip-effect="darkTable">
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('出资人类型')" align="center" prop="investorsType" :formatter="investorsTypeOptionsFormat" min-width="140" show-overflow-tooltip />
      <el-table-column :label="$t('出资人名称')" align="center" prop="investorName" min-width="180" show-overflow-tooltip />
      <el-table-column :label="$t('本金') + $t('金额单位')" align="center" prop="principalCost">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.principalCost, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('Hurdle') + $t('金额单位')" align="center" prop="hurdleTheory" min-width="120">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.hurdleTheory, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('追赶条款') + $t('金额单位')" align="center" min-width="130" prop="chaseTerms">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.chaseTerms, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('剩余分配LP') + $t('金额单位')" align="center" min-width="130" prop="surplusLp">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.surplusLp, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('剩余分配GP') + $t('金额单位')" align="center" min-width="130" prop="surplusGp">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.surplusGp, 'w') }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import {
  findCapitalAccountList
} from '@/api/fund/fp/fundFpMain'
import { listFundInvestorAll } from '@/api/fund/investor/fundInvestor'

export default {
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 基金分配主表表格数据
      fundCapitalAccountList: [],
      investorsTypeOptions: [],
      // 出资人下拉
      investorOptions: [],
      // 查询参数
      queryParams: {
        fundId: this.$route.query.id,
        investorId: this.investorId,
        pageNum: 1,
        pageSize: 50
      }

    }
  },
  created() {
    // 出资人类型字典
    this.getDicts('fund_investor_type').then(response => {
      response.data.forEach(item => {
        this.investorsTypeOptions.push(item)
      })
    })
    this.getAllInvestor()
    this.getList()
  },
  methods: {
    /** 查询基金分配主表列表 */
    getList() {
      this.loading = true
      findCapitalAccountList(this.queryParams).then(response => {
        this.fundCapitalAccountList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    getAllInvestor() {
      // 获取所有出资人
      listFundInvestorAll(this.queryParams).then(res => {
        this.investorOptions = res.data
      })
    },
    // 出资人类型
    investorsTypeOptionsFormat(row) {
      return this.selectDictLabel(this.investorsTypeOptions, row.investorsType)
    },
    // 分配类型字典翻译
    fpTypeFormat(row) {
      var result = ''
      var fpType = row.fpType
      if (fpType !== undefined && fpType !== null && fpType !== '') {
        fpType = fpType.split(',')
        result = []
        fpType.forEach(item => {
          result.push(this.selectDictLabel(this.fpTypeOptions, item))
        })
        result = result.join(',')
      }
      return result
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        fundId: this.$route.query.id,
        fpType: undefined,
        fpQc: undefined,
        fpTime: undefined,
        fpTotalAmount: undefined,
        currency: undefined,
        interestRate: undefined,
        interestDay: undefined,
        balanceLp: undefined,
        catchClauseLp: undefined,
        fpWay: undefined,
        investorShareWay: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        delFlag: undefined,
        remark: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.queryHandle()
    }

  }
}
</script>

